<?php
/**
 * Created by PhpStorm.
 * User: ZCY
 * Date: 2018/11/21
 * Time: 17:58
 */

require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
$connection = new AMQPStreamConnection('192.168.33.69', 5672, 'zcy', '196000');
$channel = $connection->channel();

$channel->exchange_declare('direct_logs', 'direct', false, true, false);   //生成或获取交换机

$channel->queue_declare("direct_yellow_blue", false, true, false, false);         //生成队列或获取队列
$channel->queue_bind("direct_yellow_blue", 'direct_logs', "yellow");             //队列绑定交换机，并制定路由
$channel->queue_bind("direct_yellow_blue", 'direct_logs', "blue");             //队列绑定交换机，并制定路由

echo ' [*] Waiting for logs. To exit press CTRL+C', "\n";

$callback = function($msg){
    echo ' [x] ',$msg->delivery_info['routing_key'], ':', $msg->body, "\n";
};

$channel->basic_consume("direct_yellow_blue", '', false, false, false, false, $callback);

while(count($channel->callbacks)) {
    $channel->wait();
}
$channel->close();
$connection->close();

